using DB.FreeSQL.Model;

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();

builder.Services.AddSingleton(x => {
    return new FreeSql.FreeSqlBuilder()
        .UseConnectionString(FreeSql.DataType.Sqlite, @"Data Source=freedb.db")
        .UseMonitorCommand(cmd => Console.WriteLine($"Sql：{cmd.CommandText}")) //监听SQL语句
        .UseAutoSyncStructure(true) //自动同步实体结构到数据库，FreeSql不会扫描程序集，只有CRUD时才会生成表。
        // .UseLazyLoading(true)
        // .UseSlave(freeSql.SlaveConnections.Select(x => x.ConnectionString).ToArray())  //集群
        .Build();
});


var app = builder.Build();

// 初始化数据库: 同步表，种子数据,FluentAPI等
using IServiceScope scope = app.Services.CreateScope();
scope.ServiceProvider.GetRequiredService<IFreeSql>().CodeFirst
    .SyncStructure(typeof(Blog));

app.MapControllers();
app.Run();